'use strict';

var PeerQueue = function (maxSize) {
    this.maxSize = maxSize || 200;
    this.reqs = [];
};

PeerQueue.prototype.push = function (peer) {
   if(this.reqs.length < this.maxSize) {
        const index = this.reqs.findIndex(v => v.infohash.toString('hex') === peer.infohash.toString('hex'))
        if(index > -1) return
        this.reqs.push(peer)
   }
};

PeerQueue.prototype.shift = function () {
    return this.reqs.shift()
};

PeerQueue.prototype.length = function () {
    return this.reqs.length;
};

module.exports = PeerQueue;